/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Offer;

import java.io.FileNotFoundException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.swing.JButton;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;
import javax.xml.stream.XMLStreamException;

/**
 *
 * @author c10mjn
 */
public class OfferTableModel implements TableModel{
    private static final String[] columnNames = {"Destination", "Date of departure", "Price", " "};
    private List<Offer> offerList;

    public OfferTableModel() throws FileNotFoundException,
            XMLStreamException, ParseException{
        this.offerList = Collections.synchronizedList(new ArrayList<Offer>());
        
        this.offerList = OfferHandler.getInstance().getList();
        
    }
    @Override
    public int getRowCount() {
        return this.offerList.size();
    }

    @Override
    public int getColumnCount() {
        return this.columnNames.length;
    }

    @Override
    public String getColumnName(int columnIndex) {
        return this.columnNames[columnIndex];
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
       switch(columnIndex){
           case 0:
               return String.class;
           case 1:
               return java.util.Calendar.class;
           case 2:
               return String.class;
           case 3:
               return javax.swing.JButton.class;
           default:
               return null;
       }
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        
        Offer temp = this.offerList.get(rowIndex);
        if(temp != null){
        switch(columnIndex){
            case 0:                
                return temp.getDestinationName();            
            case 1:                
                return temp.getOutDate();                
            case 2:
                return temp.getCurrentPrice();
            case 3:
                return new JButton("HEJ");               
            default:
                return null;
        }
        
        } else {
            return null;
        }
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        
    }

    @Override
    public void addTableModelListener(TableModelListener l) {
        
    }

    @Override
    public void removeTableModelListener(TableModelListener l) {
        
    }

}
